<?php
class Schedule_Form_Schedule_Add extends Promotor_Form_Scaffold {
	public function init() {
		$this->setMethod('post');
		$this->setAttrib('enctype', Zend_Form::ENCTYPE_MULTIPART);

		$this->addPrefixPath('Promotor_Form_Decorator_','Promotor/Form/Decorator', self::DECORATOR);
		
		$this->addPrefixPath('KontorX_Form_Decorator_','KontorX/Form/Decorator', self::DECORATOR);
		$this->addPrefixPath('KontorX_Form_Element_','KontorX/Form/Element', self::ELEMENT);

		$this->_addDefaultForm();
	}
	

	/**
     * @return Zend_Form_SubForm
     */
    protected function _addDefaultForm() {
    	$subForm = new Zend_Form_SubForm();

    	$subForm->addDecorators($this->getDecorators());
        $subForm->setAttribs(array(
            'legend' => 'Terminarz',
        ));

        $subForm
        	->addElement(
                'text',
                'name',
                array(
                    'label' => 'Nazwa terminarza',
                    'required'  => true,
                	'filters' => array(
                		'strtrim' => new Zend_Filter_StringTrim(),
                	),
                	'validators' => array(
                		'strlen' => new Zend_Validate_StringLength(5, 50)
                	)
                )
            )
            ->addElement(
                'textarea',
                'description',
                array(
                    'label' => 'Opis',
                    'required'  => true,
                	'filters' => array(
                		'strtrim' => new Zend_Filter_StringTrim(),
                	)
                )
            )
            ->addElement(
                'text',
                'username',
                array(
                    'label' => 'Nazwa użytkownika terminarza',
                    'required'  => true,
                	'description' => 'Nazwa użytkownika terminarza wymagana jest do zalogowania sie do panelu klienta oraz identyfikacji terminarza. Musi być unikalna.',
                	'filters' => array(
                		'strtrim' => new Zend_Filter_StringTrim(),
                		'rewrite' => new KontorX_Filter_Word_Rewrite()
                	),
                	'validators' => array(
                		'strlen' => new Zend_Validate_StringLength(3, 10),
                		'db_no_exsists' => new Zend_Validate_Db_NoRecordExists(
                			'schedule_schedule', 'username', array(
                				'field' => 'id',
                				'value' => current($this->getPrimaryKey())))
                	)
                )
            )
            ->addElement(
                'Password',
                'password',
                array(
                    'label'      => 'Hasło',
	                'required'  => true,
                    'filters' => array(
                		'strtrim' => new Zend_Filter_StringTrim()
                	),
                	'validators' => array(
                		'strlen' => new Zend_Validate_StringLength(4),
                		'strlen' => new Zend_Validate_Identical(@$_POST['default']['repassword'])
                	)
				)
            )
            ->addElement(
                'Password',
                'repassword',
                array(
                    'label'      => 'Powtórz hasło',
                	'ignore' 	 => true,
                    'filters' => array(
                		'strtrim' => new Zend_Filter_StringTrim()
                	),
				)
            );

        $this->addSubForm($subForm, 'default');
    }
}